import pytest
from selenium import webdriver
from time import sleep


class TestLogin:

    def setup_class(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get("http://127.0.0.1")

    def teardown_class(self):
        sleep(2)
        self.driver.quit()

    def setup(self):
        self.driver.get("http://127.0.0.1")
        self.driver.find_element("link text", "登录").click()

    def teardown(self):
        pass

    def test_account_no_exist(self):
        self.driver.find_element("id", "username").send_keys("15021241001")
        self.driver.find_element("id", "password").send_keys("123456")
        self.driver.find_element("id", "verify_code").send_keys("8888")
        self.driver.find_element("class name", "login_bnt").click()
        msg = self.driver.find_element("class name", "layui-layer-content").text
        assert msg == "账号不存在!"

    def test_wrong_password(self):
        self.driver.find_element("id", "username").send_keys("15021241000")
        self.driver.find_element("id", "password").send_keys("12345")
        self.driver.find_element("id", "verify_code").send_keys("8888")
        self.driver.find_element("class name", "login_bnt").click()
        msg = self.driver.find_element("class name", "layui-layer-content").text
        # assert msg == "账户名不存在或密码不匹配，请重新输入！"
        assert msg == "密码错误!"


if __name__ == '__main__':
    pytest.main(["-sv", "tpshop_login_2.py"])
